package com.hospital.hospitalpatientservice.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.common.dto.SickpersonDto;
import com.hospital.common.vo.ResultEntity;
import com.hospital.hospitalpatientservice.entity.Sickperson;
import com.hospital.hospitalpatientservice.service.ISickpersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;

/**
 * <p>
 * 患者表; InnoDB free: 4096 kB; (`source_id`) REFER `hospital/source`(`id`); (`marita 前端控制器
 * </p>
 *
 * @author handingfei
 * @since 2020-10-21
 */
@RestController
@RequestMapping("/sickperson")
@Slf4j
public class SickpersonController {

    @Autowired
    private ISickpersonService iSickpersonService;

    @RequestMapping("/list")
    public ResultEntity list(Page page, SickpersonDto vo){

        IPage<Sickperson> list = iSickpersonService.getlist(page,vo);

        log.info("输出~~~~~~"+list+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        return ResultEntity.ok("200","成功",list);
    }

    @RequestMapping("/save")
    @Transactional
    public boolean save(@RequestBody Sickperson sickperson){

        sickperson.setCreatetime(new Date());
        sickperson.setDoctorId(4);
        boolean save = iSickpersonService.saveOrUpdate(sickperson);
        System.err.println(save);
        return true;
    }

    @RequestMapping("/update")
    @Transactional
    public ResultEntity update(@RequestBody SickpersonDto sickpersonDto){

        sickpersonDto.setCreatetime(new Date());
        sickpersonDto.setDoctorId(4);
        iSickpersonService.updsickPerson(sickpersonDto);

        return ResultEntity.ok("200","成功");
    }

    @RequestMapping("/delete")
    public boolean delete(Integer[] ids){

        try{
            iSickpersonService.removeByIds(Arrays.asList(ids));
            return true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

}

